package revise.Class_and_Object_One;

//四、类的创建与初始化
public class Date {
    public int year;
    public int month;
    public int day;

    //三、this关键字
    //来表明哪些是成员变量
    public void setDate(int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
    }
    public void printDate(){
        System.out.println(year + "-" + month + "-" + day);
    }




    //五、构造方法

    //默认的构造方法
    public Date(){

    }
    //第二个构造方法
    public Date(int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public static void main(String[] args) {
        Date date1 = new Date();
        date1.setDate(2024,12,31);
        date1.printDate();

        Date date2 = new Date(2025,1,1);
        date2.printDate();
        System.out.println(date1);

    }

    //六、打印对象

    //使用to String方法
    //
    @Override
    public String toString() {
        return "Date{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}
